package com.von.nhcf.util;

import javax.servlet.http.HttpServletRequest;

/**
 * 判断请求的类型
 * @author von
 */
public class RequestTypeAnalysisUtil {
    /**
     * 判断请求是否为json类型，也是就是是否为Ajax
     * @param request : HttpServletRequest获取请求头信息
     * @return true : Ajax request, false : normal request
     */
    public static boolean isAjax(HttpServletRequest request) {
        String acceptValue = request.getHeader("Accept");
        String xRequestedWithValue = request.getHeader("X-Requested-With");

        return "XMLHttpRequest".equals(xRequestedWithValue) ||
                (acceptValue != null && acceptValue.contains("application/json"));
    }
}
